package ooday04;

/** 测试类 */
public class Test {

    public static void main(String[] args) {
        //多态的演示应用2
//        Mastrer mastrer = new Mastrer();
//        Dog dog = new Dog("小黑",2,"黑");
//        Fish fish = new Fish("金龙鱼",2,"黄");
//        Chick chick = new Chick("金毛",2,"金");
//        mastrer.feed(dog);
//        mastrer.feed(fish);
//        mastrer.feed(chick);

        Animal[] animals = new Animal[5];
        animals[0]  =new Dog("小黑",2,"黑");
        animals[1]  =new Dog("金毛",2,"金");
        animals[2]  =new Fish("金龙鱼",1,"黄");
        animals[3]  =new Chick("小花",2,"花");
        animals[4]  =new Fish("金鱼",2,"金");
        for (int i= 0; i< animals.length;i++){
            animals[i].drink();
            animals[i].eat();
            if (animals[i] instanceof Dog){
                Dog dog = (Dog) animals[i];
                dog.lookHome();
                dog.swim();
            }
            if (animals[i] instanceof Chick){
                Chick chick = (Chick) animals[i];
                chick.layEggs();
            }
            if (animals[i] instanceof InterFaceDemo2){
                InterFaceDemo2 z = (InterFaceDemo2) animals[i];
                z.swim();
            }
        }
    }
}




















